package org.brisling.medical.service;

import java.util.List;

import org.brisling.authorize.shiro.ShiroSecurityService;
import org.brisling.base.domain.ListDomain;
import org.brisling.common.ConstSysParam;
import org.brisling.medical.domain.MedicalRank;
import org.brisling.medical.repository.RankRepo;
import org.brisling.medical.service.base.BaseMedicalFlowService;
import org.brisling.workflow.domain.VOHistoric;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
@RequestMapping("/rank")
/**
 * 医疗服务排名类质询服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
public class RankService extends BaseMedicalFlowService<MedicalRank>{
	
	@Autowired
	private ShiroSecurityService shiroSecurityService;			
	@SuppressWarnings("unused")
	@Autowired
	private RankRepo baseFlowRepo;	
	
//	@Autowired
//	private ShiroSecurityService shiroSecurityService;	
	
	public RankService(){
		this.clazz = MedicalRank.class;
		this.moduleName = ConstSysParam.MODULE_RECIPEL;		
	}
	
		
	/**
	 * 获取业务主页面 
	 * @return
	 */
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return getBizMainPage();
	}
	
	/**
	 * 获取业务编辑页面
	 * @return
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return getBizEditPage();
	}
	
	/**
	 * 返回缺陷记录流程实例id的执行记录
	 * @param procInstId 流程实例id
	 * @return List<HistoricTaskInstance> 流程实例执行记录
	 */
	@RequestMapping("/flowHistorics.action")
	public List<VOHistoric> getHistoricByProcInstId(@RequestParam(value="flowInstId",required=false) String procInstId){
		return super.getHistoricByProcInstId(procInstId);
	}
	
	/**
	 * 返回缺陷记录流程实例id的执行记录
	 * @param procInstId 流程实例id
	 * @return List<HistoricTaskInstance> 流程实例执行记录
	 */
	@RequestMapping("/flowHistoricsListDomain.action")
	public ListDomain<VOHistoric> getBizHistoricListDomainByProcInstId(@RequestParam(value="flowInstId",required=false) String procInstId){
		return super.getHistoricListDomainByProcInstId(procInstId);
	}
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/flowListDomain.action")
	public ListDomain<MedicalRank> getListDomain(
			@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="sort",required=false) String sort,
			@RequestParam(value="fullBizcode",required=false) String fullBizcode){
		
		
			return super.getListDomain(page, rows, sort, fullBizcode);
			
	}
	
	
	/**
	 * 分页查询用户列表页面
	 * @param deptid
	 * @param page
	 * @param rows
	 * @param sort
	 * @return
	 */
	@RequestMapping("/flowList.action")
	public List<MedicalRank> getPagedFlowRows(
			@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="sort",required=false) String sort,			
			@RequestParam(value="fullBizcode",required=false) String fullBizcode
			){		
		
		return super.getPagedFlowRows(page, rows, sort, fullBizcode);			
	}
	
	/**
	 * 删除人员信息
	 * @param id
	 */
	@RequestMapping("/flowDel.action")
	public String delRow(@RequestParam(value="id",required=false) Long id){
		return super.del(id);		 
	}
	
	
	/**
	 * 保存缺陷记录
	 * @param id
	 */
	@RequestMapping("/flowSave.action")
	public MedicalRank save(@RequestBody String body){
		MedicalRank obj = bodyToObj(body, MedicalRank.class);		
		return this.saveFlowEntity(shiroSecurityService.getCurrentUserid().toString(),obj);
	}
	
	/**
	 * 签收记录
	 * @param flowInstId	流程实例id
	 * @param flowTaskId	流程节点id
	 * @param signInfo		签收信息
	 * @param body
	 * @return
	 */
	@RequestMapping("/flowSign.action")
	public String saveSingInfo(@RequestParam(value="flowInstId",required=false) String flowInstId,
			@RequestParam(value="flowTaskId",required=false) String flowTaskId,
			@RequestParam(value="signInfo",required=false) String signInfo,
			@RequestBody String body){
		
//		String uid = shiroSecurityService.getCurrentUserid().toString();
		String uid = "1";
		return super.saveSignInfo(uid, flowInstId,flowTaskId, signInfo);
	}
	
	/**
	 * 流程执行
	 * @param flowInstId	流程实例id
	 * @param flowTaskId	流程任务节点id
	 * @param signInfo		签收信息
	 * @param body
	 * @return
	 */
	@RequestMapping("/flowTaskComplete.action")
	public String saveTaskComplete(
			@RequestParam(value="flowInstId",required=false) String flowInstId,
			@RequestParam(value="flowTaskId",required=false) String flowTaskId,
			@RequestParam(value="signInfo",required=false) String signInfo,
			@RequestBody String body){
		
//		String uid = shiroSecurityService.getCurrentUserid().toString();
//		String uid = "1";
		return super.completeTaskAndCandidateById(shiroSecurityService.getCurrentUserid().toString(),flowInstId, signInfo);
		
	}
	
	
	
	
}
